const mongoose=require('mongoose');
const config=require('../config');
const skus=require('../clean/skus');
const Book=require('../models/book');
const Comment=require('../models/comment');
const bookUpdates=require('./bookUpdates');
const commentUpdates=require('./commentUpdates');

mongoose.connect(config.db);

(async function(){
    (function commentIIFE(){
        let comment=commentUpdates.pop();
        if(!comment)return console.log('Comment updated!!'),process.exit();

        let field=comment.field;

        //Comment.update({sku:comment.sku},{[`comments.${comment.idx}.smalls`]:comment.images});

        Comment.update({sku:comment.sku},{[`comments.${comment.idx}.${comment.field}`]:comment.data},(err,ret)=>{
            if(err)throw err;
            console.log(comment.sku,field,ret);
            commentIIFE();
        });

    })();

})();





/*
(async function(){
    const fields={
        previews:'previewnames',
        thumbs:'thumbnames'
    };

    (function bookIIFE(){
        let book=bookUpdates.pop();
        if(!book)return console.log('Book updated!!'),process.exit();

        let field=fields[book.field];
        Book.update({sku:book.sku},{[field]:book.data},(err,ret)=>{
            if(err)throw err;
            console.log(book.sku,field,ret);
            bookIIFE();
        });

    })();

})();
*/